//
//  VehicleSettlementViewController.m
//  HondaPro_2
//
//  Created by ht on 13-6-24.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "VehicleSettlementViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "webConfig.h"
#import "webService.h"
#import "SVProgressHUD.h"
#import "MyAFNetWorkManager.h"
#import "MJRefresh.h"

#import "HJRepairSettlementViewController.h"

@interface VehicleSettlementViewController ()
{
    BOOL _usedCarChoose;
    NSInteger from;
    NSInteger to;
}

@end

@implementation VehicleSettlementViewController

@synthesize settlementView = _settlementView;
@synthesize choosebutton1 = _choosebutton1;
@synthesize choosebutton2 = _choosebutton2;

@synthesize carframe = _carframe;
@synthesize licenseplate = _licenseplate;
@synthesize customer = _customer;

@synthesize usedCarButton = _usedCarButton;      //是否二手车辆选择按钮

@synthesize settlementbutton1 = _settlementbutton1;
@synthesize settlementbutton2 = _settlementbutton2;
@synthesize settlementbutton3 = _settlementbutton3;
@synthesize settlementbutton4 = _settlementbutton4;
@synthesize settlementbutton5 = _settlementbutton5;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
//   [self query:self.queryButton];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //初始化 from-to
    from = 1;
    to = 10;
    
    self.carTypeArray = [[NSMutableArray alloc]init];
    self.evaluatorPersonArray = [[NSMutableArray alloc]init];
    self.workOrderStatusArray = [[NSMutableArray alloc]init];
    
     self.vehicleCxunArray = [NSMutableArray arrayWithCapacity:5];
    //服务接待列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(searchJobsheet:) name:SEARCHJOBSHEET object:Nil];
    //获取车种名列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCarClass:) name:GETCARCLASSNAMELIST object:nil];
    //获取车型列表
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCarType:) name:GETCARTYPENAMELIST object:nil];
    //估价人
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(evaluatorPerson:) name:GETEVALUATORPERSONNAMELIST object:nil];
    //直属店
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shopIdList:) name:GETSHOPNAMELIST object:nil];
    //结算单查询
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getSettlementDetail:) name:GETSETTLEMENTDETAIL object:Nil];

    
    [self loadbasicbuttonPicture];         //界面固定按钮
    [self loadcallbuttonPicture];          //需要调用的按钮
    [self loadSecondPartPicture];          //固定标题
    [self loadcallfixedPicture];           //文本输入
    
    [self loadNewTitleLabelPicture];
    
    self.settlementView = [[UITableView alloc]initWithFrame:CGRectMake(65, 350, 900, 315) style:UITableViewStylePlain];
    [self.settlementView setDataSource:self];
    [self.settlementView setDelegate:self];
    [self.view addSubview:self.settlementView];
    
    __unsafe_unretained UITableView *table = self.settlementView;
    table.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        to = 10;
//        [self.vehicleCxunArray removeAllObjects];
        [self query:nil];
        [table.mj_header endRefreshing];
    }];
    
    
    table.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        to = to+10;
        [self query:nil];
        [table.mj_footer endRefreshing];
    }];
    
    strCurrJobSheetId = nil;
    self.isHonda = YES;
    self.isxiu = YES;
    
    self.carTypeId = @"< 空 >";
    self.carClassId= @"< 空 >";
    self.evaluatorPersonId= @"< 空 >";
    self.shopIdId =  @"< 空 >";
    
}
-(void)loadcallfixedPicture
{

    self.carframe = [self setupTextFieldWithFrame:CGRectMake(525, 133, 180, 35)];//车架号
    self.carframe.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
    self.licenseplate = [self setupTextFieldWithFrame:CGRectMake(255, 133, 180, 35)];//车牌号
//    self.licenseplate.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
    //初始化车牌号
//    self.licenseplate.text = [MainMenuDataModel sharedMainMenuDataModel].strCurrentPlateNumber == nil ? @"" : [MainMenuDataModel sharedMainMenuDataModel].strCurrentPlateNumber;
    
    self.customer = [self setupTextFieldWithFrame:CGRectMake(255, 183, 180, 35)];//客户名
    
//    [self setupDropdownLabelWithFrame:CGRectMake(515, 233, 180, 35)]; //零售店
//    self.settlementbutton1 = [self setupDropdownButtonWithFrame:CGRectMake(516, 234, 178, 33) action:@selector(settlementbutton1:)];//零售店
    
    [self setupDropdownLabelWithFrame:CGRectMake(775+20, 133, 180, 35)];  //车型
    self.settlementbutton2 = [self setupDropdownButtonWithFrame:CGRectMake(776+20, 134, 178, 33) action:@selector(settlementbutton2:)];//车型
    
//    [self setupDropdownLabelWithFrame:CGRectMake(775+20, 183, 180, 35)];  //状态
//    self.settlementbutton3 = [self setupDropdownButtonWithFrame:CGRectMake(776+20, 184, 178, 33) action:@selector(settlementbutton3:)];//状态
    
//    [self setupDropdownLabelWithFrame:CGRectMake(255, 233, 180, 35)];   //车种名
//    self.settlementbutton4 = [self setupDropdownButtonWithFrame:CGRectMake(256, 234, 178, 33) action:@selector(settlementbutton4:)];//车种名
//    515
    [self setupDropdownLabelWithFrame:CGRectMake(525, 183, 180, 35)];   //估价人
    
    
    self.settlementbutton5 = [self setupDropdownButtonWithFrame:CGRectMake(526, 184, 178, 33) action:@selector(settlementbutton5:)];//服务专员
}

//*********需要调用的按钮
-(void)loadcallbuttonPicture
{
    self.choosebutton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.choosebutton1 setFrame:CGRectMake(70, 130, 35, 35)];
    [self.choosebutton1 setImage:[UIImage imageNamed:@"选择中.png"] forState:UIControlStateNormal];
    [self.choosebutton1 addTarget:self action:@selector(choosebutton1:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.choosebutton1];

    self.choosebutton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.choosebutton2 setFrame:CGRectMake(70, 180, 35, 35)];
    [self.choosebutton2 setImage:[UIImage imageNamed:@"选择空.png"] forState:UIControlStateNormal];
    [self.choosebutton2 addTarget:self action:@selector(choosebutton2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.choosebutton2];
    
//    self.usedCarButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.usedCarButton setFrame:CGRectMake(760, 242, 32, 33)];
//    [self.usedCarButton setImage:[UIImage imageNamed:@"对号1.png"] forState:UIControlStateNormal];
////    [self.usedCarButton addTarget:self action:@selector(usedCarButton:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:self.usedCarButton];
}
//-(void)usedCarButton:(id)sender
//{
//    if(self.isxiu == NO)
//    {
//        self.isxiu = YES;
//        [self.usedCarButton setImage:[UIImage imageNamed:@"对号1.png"] forState:UIControlStateNormal];
//    }
//    else
//    {
//        self.isxiu = NO;
//        [self.usedCarButton setImage:[UIImage imageNamed:@"对号框.png"] forState:UIControlStateNormal];
//    }
//}

-(void)choosebutton1:(id)sender
{
    self.isHonda = YES;
    [self.choosebutton1 setImage:[UIImage imageNamed:@"选择中.png"] forState:UIControlStateNormal];
    [self.choosebutton2 setImage:[UIImage imageNamed:@"选择空.png"] forState:UIControlStateNormal];
}
-(void)choosebutton2:(id)sender
{
    self.isHonda = NO;
    [self.choosebutton2 setImage:[UIImage imageNamed:@"选择中.png"] forState:UIControlStateNormal];
    [self.choosebutton1 setImage:[UIImage imageNamed:@"选择空.png"] forState:UIControlStateNormal];
}

-(NSMutableDictionary *)readershuDICimform
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *str=[path stringByAppendingPathComponent:@"Dic.text"];
    dic=[NSMutableDictionary dictionaryWithContentsOfFile:str];
    //nslog(@"%@",dic);
    return dic;
}

#pragma mark - 零售店按钮的回调方法
-(void)settlementbutton1:(id)sender
{
    webService *web = [[webService alloc] init];
    web.methodName = GETSHOPNAMELIST;
    [web commonGetSharedRequest:GETSHOPNAMELIST wsparas:nil];
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:222 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    //[DDPopoverBackgroundView setShadowEnabled:NO];//关闭箭头
    [DDPopoverBackgroundView setContentInset:1.0];
    
    
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.settlementbutton1.frame.size.width, 280)];
    
    [self.popCon presentPopoverFromRect:CGRectMake(30, 15, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
-(void)shopIdList:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.shopArray = [theJson objectForKey:@"results"];
    NSMutableArray *carClassArray=[[NSMutableArray alloc] init];
    [carClassArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carClassArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"shopId"]];
    }
    
    contentCon.list = carClassArray;
    [contentCon.myTableView reloadData];
}

#pragma mark - 车型按钮的回调方法
-(void)settlementbutton2:(id)sender
{
    
//    webService *web=[[webService alloc] init];
//    web.methodName = GETCARTYPENAMELIST;
//    [web commonGetSharedRequest:GETCARTYPENAMELIST wsparas:nil];
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    
    contentCon.delegate = self;
    contentCon.btnSender=self.settlementbutton2;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:222 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.settlementbutton2.frame.size.width, 280)];
    [self.popCon presentPopoverFromRect:CGRectMake(30, 15, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    NSArray *zidianArr=[self readershuDICimform][@"MODEL"];
    NSMutableArray *modelArr = [[NSMutableArray alloc]init];
    [self.carTypeArray removeAllObjects];
    
    for(NSDictionary *dic in zidianArr)
    {
        [modelArr addObject:dic[@"MODEL_NAME"]];
        [self.carTypeArray addObject:dic[@"MODEL_CODE"]];
    }
     [modelArr insertObject:@"< 空 >" atIndex:0];
    contentCon.list = modelArr;
    
    [contentCon.myTableView reloadData];
}
-(void)getCarType:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.carTypeArray = [theJson objectForKey:@"results"];
    NSMutableArray *carTypeArray=[[NSMutableArray alloc] init];
    [carTypeArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carTypeArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"carTypeName"]];
    }
    contentCon.list = carTypeArray;
    
    [contentCon.myTableView reloadData];
}

#pragma mark - 状态按钮的回调方法
//-(void)settlementbutton3:(id)sender
//{
//    if (!contentCon) {
//        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
//    }
//    contentCon.delegate = self;
//    contentCon.btnSender=sender;
//    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
//    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
//    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
//    [DDPopoverBackgroundView setArrowHeight:15.0];
//    [DDPopoverBackgroundView setContentInset:1.0];
//    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
//    [self.popCon setPopoverContentSize:CGSizeMake(self.settlementbutton3.frame.size.width, 120)];
//      [self.popCon presentPopoverFromRect:CGRectMake(30, 10, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
//    
//    
////    NSMutableArray *carTypeArray=[[NSMutableArray alloc]initWithCapacity:10];
////    [carTypeArray addObject:@"完工检查"];
////    [carTypeArray addObject:@"结 算"];
////    [carTypeArray addObject:@"会计打印"];
////    //添加全部选项
////    [carTypeArray addObject:@"全部"];
//
//    NSArray *zidianArr=[self readershuDICimform][@"TM_RO_STATUS"];
//    NSMutableArray *modelArr = [[NSMutableArray alloc]init];
//    [self.workOrderStatusArray removeAllObjects];
//    
//    for(NSDictionary *dic in zidianArr)
//    {
//        [modelArr addObject:dic[@"NAME"]];
//        [self.workOrderStatusArray addObject:dic[@"CODE"]];
//    }
//    
//    contentCon.list = modelArr;
//    
//    [contentCon.myTableView reloadData];
//}
#pragma mark - 车种名按钮的回调方法
-(void)settlementbutton4:(id)sender
{
//    webService *web=[[webService alloc] init];
//    web.methodName = GETCARCLASSNAMELIST;
//    [web commonGetSharedRequest:GETCARCLASSNAMELIST wsparas:nil];
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    
    contentCon.delegate = self;
    contentCon.btnSender=self.settlementbutton4;
    
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:222 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    //[DDPopoverBackgroundView setShadowEnabled:NO];//关闭箭头
    [DDPopoverBackgroundView setContentInset:1.0];
    
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.settlementbutton4.frame.size.width, 280)];
    [self.popCon presentPopoverFromRect:CGRectMake(28, 15, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    
   
    contentCon.list = nil;
    [contentCon.myTableView reloadData];
}
-(void)getCarClass:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.carClassArray = [theJson objectForKey:@"results"];
    NSMutableArray *carClassArray=[[NSMutableArray alloc] init];
    [carClassArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carClassArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"carClassName"]];
    }
    contentCon.list = carClassArray;
    [contentCon.myTableView reloadData];
}
//下拉列表按钮点击的回调
-(void)selectDelegate:(NSInteger)row btn:(UIButton *)btn
{
  
    if(row > 0)
    {
        if (btn==self.settlementbutton4)
        {
            self.carClassId = [[self.carClassArray objectAtIndex:row-1] objectForKey:@"carClassCode"];
            
        }
        if (btn == self.settlementbutton2)
        {
//            self.carTypeId = [[self.carTypeArray objectAtIndex:row-1]objectForKey:@"carTypeId"];
            self.carTypeId =[self.carTypeArray objectAtIndex:row-1];
        }
        if(btn == self.settlementbutton5)
        {
//            self.evaluatorPersonId = [[self.evaluatorPersonArray objectAtIndex:row-1]objectForKey:@"evaluatorPersonId"];
            self.evaluatorPersonId = [self.evaluatorPersonArray objectAtIndex:row-1];
        }
        if(btn == self.settlementbutton1)
        {
            self.shopIdId = [[self.shopArray objectAtIndex:row-1]objectForKey:@"shopId"];
        }
//    if (btn == self.settlementbutton3) {
//        self.workorderID =[self.workOrderStatusArray objectAtIndex:row];
//    }
  }
    else
    {
//        if (btn==self.settlementbutton4)
//        {
//            self.carClassId = @"< 空 >";
//        }
        if(btn == self.settlementbutton2)
        {
            self.carTypeId = @"";
        }
        if(btn == self.settlementbutton5)
        {
            self.evaluatorPersonId = @"";
        }
//        if(btn == self.settlementbutton1)
//        {
//            self.shopIdId = @"< 空 >";
//        }
    }
    NSLog(@"---------%@----%@",self.carTypeId,self.evaluatorPersonId);
    [self.popCon dismissPopoverAnimated:YES];
    self.popCon = nil;
}

#pragma mark - 估价人按钮的回调方法
-(void)settlementbutton5:(id)sender
{
//    webService *webcon = [[webService alloc] init];
//    webcon.methodName = GETEVALUATORPERSONNAMELIST;
//    [webcon commonGetSharedRequest:GETEVALUATORPERSONNAMELIST wsparas:Nil];
    
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender = sender;
    
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:222 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    //[DDPopoverBackgroundView setShadowEnabled:NO];//关闭箭头
    [DDPopoverBackgroundView setContentInset:1.0];
    
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.settlementbutton5.frame.size.width, 280)];
    
    [self.popCon presentPopoverFromRect:CGRectMake(30, 15, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    
    NSArray *zidianArr=[self readershuDICimform][@"SERVICE_ADVISOR"];
    NSMutableArray *modelArr = [[NSMutableArray alloc]init];
    [self.evaluatorPersonArray removeAllObjects];
    
    for(NSDictionary *dic in zidianArr)
    {
        [modelArr addObject:dic[@"NAME"]];
        [self.evaluatorPersonArray addObject:dic[@"CODE"]];
    }
    [modelArr insertObject:@"< 空 >" atIndex:0];
    contentCon.list = modelArr;
    
    [contentCon.myTableView reloadData];
    
}
-(void)evaluatorPerson:(NSNotification*)notification{
    
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.evaluatorPersonArray = [theJson objectForKey:@"results"];
    NSMutableArray *carClassArray=[[NSMutableArray alloc] init];
    [carClassArray addObject:@"< 空 >"];
    
    for (int i=0; i<[[theJson objectForKey:@"results"] count]; i++) {
        
        [carClassArray addObject: [[[theJson objectForKey:@"results"] objectAtIndex:i] objectForKey:@"evaluatorName"]];
    }
    contentCon.list = carClassArray;
    [contentCon.myTableView reloadData];
}

- (void) niDropDownDelegateMethod: (NIDropDown *) sender
{
    dropDown = nil;
}
#pragma mark - 查询按钮的回调方法
-(void)query:(id)sender
{
  
    strCurrJobSheetId = nil;
//    [SVProgressHUD showWithStatus:@"请等待...."];
//    webService *web=[[webService alloc] init];
//    web.methodName = SEARCHJOBSHEET;
    NSMutableDictionary * params = [[NSMutableDictionary alloc]init];
    
    NSMutableArray *paras = [[NSMutableArray alloc]init];
    if (self.licenseplate.text != nil)
    {
        NSString * str = [self.licenseplate.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [params setValue:str forKey:@"PLATE_NUMBER"];
        [paras addObject:@"plateNumber"];
        [paras addObject:self.licenseplate.text];
        
    }
    
    if (self.carframe.text != nil)
    {
        [params setValue:[self.carframe.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] forKey:@"VIN"];
        [paras addObject:@"vin"];
        [paras addObject:self.carframe.text];
    }
    if (self.customer.text != nil)
    {
        NSString * str=[self.customer.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
       
        [params setValue:str forKey:@"CUSTOMER_NAME"];
        [paras addObject:@"customerName"];
        [paras addObject:self.customer.text];
    }
    if (![self.settlementbutton2.titleLabel.text isEqualToString:@"< 空 >"])
    {
        NSLog(@"%@",self.settlementbutton2.titleLabel.text);
        [params setValue:self.carTypeId forKey:@"CAR_TYPE_ID"];
        [paras addObject:@"carTypeId"];
        [paras addObject:self.carTypeId];
    }
//    if (![self.carClassId isEqualToString:@"< 空 >"])
//    {
//        [params setValue:self.carClassId forKey:@"CAR_CLASS_CODE"];
//        [paras addObject:@"carClassCode"];
//        [paras addObject:self.carClassId];
//    }
    if (![self.settlementbutton5.titleLabel.text isEqualToString:@"< 空 >"])
    {
        [params setValue:self.evaluatorPersonId forKey:@"EVALUATOR_PERSON_ID"];
        [paras addObject:@"evaluatorPersonId"];
        [paras addObject:self.evaluatorPersonId];
    }
//    if (![self.shopIdId isEqualToString:@"< 空 >"])
//    {
//       
//        [paras addObject:@"shopId"];
//        [paras addObject:self.shopIdId];
//    }
//    if(![self.settlementbutton3.titleLabel.text isEqualToString:@"< 空 >"])
//    {
//       [params setValue:self.workorderID forKey:@"STATE_CODE"];
//    }
    
    [paras addObject:@"currentCar"];
//    if (self.isxiu == YES)
//    {
//        [params setValue:@"12781001" forKey:@"COMPLETE_TAG"];
//        [paras addObject:@"1"];
//    }else
//    {
//         [params setValue:@"12781002" forKey:@"COMPLETE_TAG"];
//        [paras addObject:@"0"];
//    }
    [paras addObject:@"warrantyCar"];
    [paras addObject:@"0"];

    [paras addObject:@"isHonda"];
    if(self.isHonda == YES)
    {
        [params setValue:@"1" forKey:@"IS_HONDA"];
        [paras addObject:@"1"];
    }else
    {
        
        [params setValue:@"0" forKey:@"IS_HONDA"];
        [paras addObject:@"0"];
    
    }
    
    [params setValue:[NSString stringWithFormat:@"%d",from] forKey:@"FROM"];
    [params setValue:[NSString stringWithFormat:@"%d",to]  forKey:@"TO"];
//    [params setValue:[NSString stringWithFormat:@"%d",self.vehicleCxunArray.count+1] forKey:@"FROM"];
//    [params setValue:[NSString stringWithFormat:@"%d",self.vehicleCxunArray.count+10] forKey:@"TO"];
    [params setValue:@"12781001" forKey:@"COMPLETE_TAG"];//默认竣工
    [params setValue:@"12551001" forKey:@"STATE_CODE"];//在修状态
    NSLog(@"--%@",params);
    
    [self.vehicleCxunArray removeAllObjects];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //api调用及返回
        [MyAFNetWorkManager postWithParam:params andAction:@"QUERY_REPAIR_ORDER_PAD" finish:^(NSData *data, NSDictionary *obj, NSError *error) {
         
            [SVProgressHUD dismiss];
         
            if (error == nil)
            {
                NSLog(@"验车结果查询 json is %@",obj);
                NSDictionary *dic = obj;
                if([[dic valueForKey:@"SUCCESS"] integerValue]==1)
                {
                    NSArray *array = [dic objectForKey:@"TT_REPAIR_ORDER"];
                 //   NSLog(@" ccccccc  %d",array.count);
                    [self.vehicleCxunArray removeAllObjects];
                    [self.vehicleCxunArray addObjectsFromArray:array];
                    [self.settlementView reloadData];
                    
                    
                 
                    
                }
            }
            else{
                [SVProgressHUD showErrorWithStatus:error.localizedDescription];
            }
            
      }];
    });
//    [web commonGetSharedRequest:SEARCHJOBSHEET wsparas:paras];
}
-(void)searchJobsheet:(NSNotification *)notifcation
{
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notifcation.object options:NSJSONReadingMutableLeaves error:Nil];
    self.vehicleCxunArray = [theJson objectForKey:@"results"];
//    NSLog(@"*!^*!^*!^*!^*!^*!^*!^%@",self.vehicleCxunArray);
    [self.settlementView reloadData];
    [SVProgressHUD dismiss];
}

#pragma mark - 返回上一页面按钮的回调方法
-(void)back:(id)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

//*****************固定标题
-(void)loadSecondPartPicture
{
    [self createLabelWithTitle:@"传祺品牌" fontSize:17 frame:CGRectMake(105, 130, 90, 40)];
    
    [self createLabelWithTitle:@"非传祺品牌" fontSize:15 frame:CGRectMake(105, 180, 80, 40)];
    
    [self createLabelWithTitle:@"车牌号:" fontSize:17 frame:CGRectMake(195, 130, 80, 40)];
    
    [self createLabelWithTitle:@"客户名:" fontSize:17 frame:CGRectMake(195, 180, 80, 40)];
    
    [self createLabelWithTitle:@"车架号:" fontSize:17 frame:CGRectMake(450, 130, 80, 40)];
    
//    [self createLabelWithTitle:@"零售店:" fontSize:17 frame:CGRectMake(450 , 230, 80, 40)];
    
//    [self createLabelWithTitle:@"车种名:" fontSize:17 frame:CGRectMake(195, 230, 80, 40)];
    
    [self createLabelWithTitle:@"服务专员:" fontSize:17 frame:CGRectMake(450, 180, 80, 40)];
    
    [self createLabelWithTitle:@"车 型:" fontSize:17 frame:CGRectMake(720, 130, 80, 40)];
    
//    [self createLabelWithTitle:@"工单状态:" fontSize:17 frame:CGRectMake(720, 180, 80, 40)];
    
//    [self createLabelWithTitle:@"是否竣工" fontSize:17 frame:CGRectMake(800, 240, 80, 40)];
}
-(void)loadNewTitleLabelPicture
{
    
    UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(65, 305, 900, 45)];
     titleView.backgroundColor = [[UIColor alloc]initWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    NSArray*ary=@[@"作业单号",@"车牌号",@"车架号",@"车型",@"车主",@"服务专员"];
    CGFloat w=titleView.mj_w/ary.count;
    int i=0;
    for (NSString*str in ary) {
        UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(i*w, 0, w, titleView.mj_h)];
          label.textColor = [UIColor grayColor];
         label.font = [UIFont fontWithName:@"ArialMT" size:16];
        label.text=str;
        label.textAlignment=NSTextAlignmentCenter;
        [titleView addSubview:label];
        i++;
    }
     [self.view addSubview:titleView];
  
   
  
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return [self.vehicleCxunArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"----------------------------------------------------%d",self.vehicleCxunArray.count);
    NSInteger row = [indexPath row];
    static NSString *indetfire = @"cell";
    VehicleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indetfire];
    if(nil == cell)
    {
        cell = [[VehicleTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetfire];
    }
 
    if(row < [self.vehicleCxunArray count])
  {
      cell.dict=[self.vehicleCxunArray objectAtIndex:row];
    }
    return cell;
}
-(NSString *)getchexing:(NSInteger)sender{
    NSString * str = [[self.vehicleCxunArray objectAtIndex:sender]objectForKey:@"MODEL"];
    NSArray *zidianArr=[self readershuDICimform][@"MODEL"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"MODEL_CODE"] isEqualToString:str]) {
            return dic[@"MODEL_NAME"];
        }
    }
    return nil;
}
-(NSString *)getCheXi:(NSInteger)sender{
    
    NSString * str = [[self.vehicleCxunArray objectAtIndex:sender]objectForKey:@"SERIES"];
    NSArray *zidianArr=[self readershuDICimform][@"SERIES"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"SERIES_CODE"] isEqualToString:str]) {
            return dic[@"SERIES_NAME"];
        }
    }
    return nil;
}
-(NSString *)getStatus:(NSInteger)sender{
    NSString * str = [[[self.vehicleCxunArray objectAtIndex:sender] objectForKey:@"STATE_NAME"] stringValue] ;
    NSArray *zidianArr=[self readershuDICimform][@"TM_RO_STATUS"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"CODE"] isEqualToString:str]) {
            return dic[@"NAME"];
        }
    }
    return nil;

}
-(NSString *)getEVALUATOR_NAME:(NSInteger)sender{
    NSString * str = [[self.vehicleCxunArray objectAtIndex:sender] objectForKey:@"EVALUATOR_NAME"] ;
    NSArray *zidianArr=[self readershuDICimform][@"SERVICE_ADVISOR"];
    for(NSDictionary *dic in zidianArr)
    {
        if ([dic[@"CODE"] isEqualToString:str]) {
            return dic[@"NAME"];
        }
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row%2 == 1)
    {
        cell.backgroundColor = [UIColor whiteColor];
    }
    else
    {
        cell.backgroundColor = [[UIColor alloc]initWithRed:226.00/255 green:226.00/255 blue:226.00/255 alpha:1];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}
#pragma mark - 点击列表push二级界面
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * ro_no =[self.vehicleCxunArray objectAtIndex:indexPath.row][@"JOB_SHEET_ID"];//获取点击行工单编号
 HJRepairSettlementViewController*vc=[HJRepairSettlementViewController new];
    vc.RO_NO=ro_no;
    [self.navigationController pushViewController:vc animated:YES];
    return;
    
    
    [SVProgressHUD showWithStatus:@"请等待...."];
    self.zuoYeDanNumber = [[self.vehicleCxunArray objectAtIndex:[indexPath row]]objectForKey:@"JOB_SHEET_ID"];//取出点击每一行的作业单号jobSheetId
    
//    webService *web = [[webService alloc]init];
//    web.methodName = GETSETTLEMENTDETAIL;
    
    NSMutableArray *canShuArray = [[NSMutableArray alloc]init];
    
    [canShuArray addObject:@"jobSheetId"];
    [canShuArray addObject:self.zuoYeDanNumber];
//    [web commonGetSharedRequest:GETSETTLEMENTDETAIL wsparas:canShuArray];
    /*
    NSMutableDictionary * canShuDic = [[NSMutableDictionary alloc]init];
    [canShuDic setValue:self.zuoYeDanNumber forKey:@"JOB_SHEET_ID"];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //api调用及返回
        [MyAFNetWorkManager postWithParam:params andAction:@"QUERY_REPAIR_ORDER_PAD" finish:^(NSData *data, NSDictionary *obj, NSError *error) {
            [SVProgressHUD dismiss];
            
            if (error == nil)
            {
                NSLog(@"验车结果查询 json is %@",obj);
                NSDictionary *dic = obj;
                if([[dic valueForKey:@"SUCCESS"] integerValue]==1)
                {
                    NSArray *array = [dic objectForKey:@"TT_REPAIR_ORDER"];
                    //                    NSLog(@" ccccccc  %d",array.count);
                    if (array.count) {
                        [self.vehicleCxunArray setArray:array];
                        [self.settlementView reloadData];
                    }
                    
                }
            }
            else{
                [SVProgressHUD showErrorWithStatus:error.localizedDescription];
            }
            
        }];
    });
     */
}
-(void)getSettlementDetail:(NSNotification *)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:nil];
    self.htHomeworkManufacturing = [[HtHomeworkManufacturing alloc]init];
//    self.htHomeworkManufacturing.homeworkData = theJson;
//    self.htHomeworkManufacturing.printZT = self.settlementbutton3.titleLabel.text;
    [self.navigationController pushViewController:self.htHomeworkManufacturing animated:YES];
}

//***********界面固定按钮
-(void)loadbasicbuttonPicture
{
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"房子.png"] forState:UIControlStateNormal];
    [backButton setFrame:CGRectMake(70, 42, 68, 40)];
    [backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    
    UILabel *jiedai = [[UILabel alloc]initWithFrame:CGRectMake(200, 45, 200, 40)];
    jiedai.text = @"验车结算";
    jiedai.backgroundColor = [UIColor clearColor];
    jiedai.textColor = [UIColor grayColor];
    jiedai.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:jiedai];
    
    UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 1000, 11)];
    image1.image = [UIImage imageNamed:@"渐变分割线.png"];
    [self.view addSubview:image1];
    
    self.queryButton = [[UIButton alloc]initWithFrame:CGRectMake(870, 55, 75, 35)];
    [self.queryButton setBackgroundImage:[UIImage imageNamed:@"ht05-1.png"] forState:UIControlStateNormal];
    [self.queryButton setTitle:@"查  询" forState:UIControlStateNormal];
    [self.queryButton setTintColor:[UIColor whiteColor]];
    self.queryButton.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.queryButton addTarget:self action:@selector(query:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.queryButton];
}

#pragma mark - 公共方法
-(void)createLabelWithTitle:(NSString *)title fontSize:(int)fontSize frame:(CGRect)frame{
    UILabel *lbl = [[UILabel alloc]initWithFrame:frame];
    lbl.text = title;
    lbl.backgroundColor = [UIColor clearColor];
    lbl.textColor = [UIColor grayColor];
    lbl.font = [UIFont fontWithName:@"ArialMT" size:fontSize];
    [self.view addSubview:lbl];
}

-(UITextField *)setupTextFieldWithFrame:(CGRect)frame{
    UITextField *txt = [[UITextField alloc]initWithFrame:frame];
    txt.borderStyle = UITextBorderStyleLine;
    txt.textColor = [UIColor grayColor];
    txt.font = [UIFont fontWithName:@"ArialMT" size:15];
    [txt setTextAlignment:NSTextAlignmentCenter];
    txt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.view addSubview:txt];
    return txt;
}

-(void)setupDropdownLabelWithFrame:(CGRect)frame{
    UILabel *label1 = [[UILabel alloc]initWithFrame:frame];
    [label1 setBackgroundColor:[UIColor clearColor]];
    label1.layer.borderColor = [[UIColor blackColor]CGColor];
    label1.layer.borderWidth = 1;
    [self.view addSubview:label1];
}

-(UIButton *)setupDropdownButtonWithFrame:(CGRect)frame action:(SEL)method
{
    UIButton *btn = [[UIButton alloc]initWithFrame:frame];
    [btn setBackgroundImage:[UIImage imageNamed:@"下拉框.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:method forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"< 空 >" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:16];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    return btn;
}

@end
